<?php
final class ActionFactory {
	private static $actions = array(
		'/' => 'MainAction',
		'/index' => 'MainAction',
		'/index.php' => 'MainAction',
		'/login' => 'LoginAction',
		'/logout' => 'LogoutAction',
		'/person/editPrivate' => 'PersonEditAction',
		'/person/updatePrivate' => 'PersonUpdateAction',
		'/person/password/setPrivate' => 'PersonPasswordSetAction',
		// действия для администратора
		'/departmenttype/index' => 'admin/DepartmentTypeListAction',
		'/departmenttype/edit' => 'admin/DepartmentTypeEditAction',
		'/departmenttype/update' => 'admin/DepartmentTypeUpdateAction',
		'/departmenttype/delete' => 'admin/DepartmentTypeDeleteAction',
		'/post/index' => 'admin/PostListAction',
		'/post/edit' => 'admin/PostEditAction',
		'/post/update' => 'admin/PostUpdateAction',
		'/post/delete' => 'admin/PostDeleteAction',
		'/person/index' => 'admin/PersonListAction',
		'/person/edit' => 'admin/PersonEditAction',
		'/person/update' => 'admin/PersonUpdateAction',
		'/person/delete' => 'admin/PersonDeleteAction',
		'/person/password/set' => 'admin/PersonPasswordSetAction',
		'/person/role/switch' => 'admin/PersonRoleSwitchAction',
		'/employee/delete' => 'admin/EmployeeDeleteAction',
		'/employee/add' => 'admin/EmployeeAddAction',
		'/department/index' => 'admin/DepartmentListAction',
		'/department/edit' => 'admin/DepartmentEditAction',
		'/department/update' => 'admin/DepartmentUpdateAction',
		'/department/delete' => 'admin/DepartmentDeleteAction',
		// действия для сотрудника отдела качества
		'/editing/process/index' => 'qualitydepartmentemployee/ProcessListAction',
		'/editing/process/edit' => 'qualitydepartmentemployee/ProcessEditAction',
		'/editing/process/update' => 'qualitydepartmentemployee/ProcessUpdateAction',
		'/editing/process/delete' => 'qualitydepartmentemployee/ProcessDeleteAction',
		'/editing/indicator/copy' => 'qualitydepartmentemployee/IndicatorCopyAction',
		'/editing/indicator/edit' => 'qualitydepartmentemployee/IndicatorEditAction',
		'/editing/indicator/update' => 'qualitydepartmentemployee/IndicatorUpdateAction',
		'/editing/indicator/delete' => 'qualitydepartmentemployee/IndicatorDeleteAction',
		'/editing/indicator/responsibility' => 'qualitydepartmentemployee/ResponsibilityAddAction',
		'/monitoring/index' => 'qualitydepartmentemployee/MonitoringAction',
		'/monitoring/indicator/indicatorAvgVal' => 'qualitydepartmentemployee/IndicatorAverageValuesAction',
		// действия для руководителя структурного подразделения
		'/editing/division/index' => 'departmenthead/IndicatorValueEditAction',
		'/editing/division/update' => 'departmenthead/IndicatorValueUpdateAction',
		'/monitoring/indicator/index' => 'departmenthead/IndicatorValueListAction'
		
	);

	public static function getAction($path) {
		if(isset(self::$actions[$path])) {
			$actionPath = self::$actions[$path];
			echo $actionPath;
			$lastSlashIndex = strrpos($actionPath, '/');
			if($lastSlashIndex !== false) {
				$lastSlashIndex++;
				$folder = substr($actionPath, 0, $lastSlashIndex);

				$class = substr($actionPath, $lastSlashIndex);

			} else {
				$folder = '';
				$class = $actionPath;
			}
			require_once $_SERVER['DOCUMENT_ROOT'].'/actions/'.$folder.$class.'.php';

			return new $class;
		}
		return null;
	}
}
?>